home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 July: Mac OS SDK / Dev.CD Jul 97 SDK1.toast / Development Kits (Disc 1) / QuickDraw GX / Programming Stuff / Sample Code / Graphics Samples / path & frames ƒ / path & frame demo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-15  |  7.3 KB  |  227 lines  |  [TEXT/KAHL]

  1. /*
  2.     Path & Frame demo 
  3.  
  4.     This application creates 3 shapes: an oval, diamond, and a path which represents an outline of an "E".  We will take these
  5.     3 shapes and combine them into one called - gOvaloidShape. We can combine these shapes by calling AddToShape (..).
  6.     
  7.     Once we have a single gxShape containing the three shapes, we can operate on the properties of these shapes as a single gxShape. 
  8.     By clicking within the content of the window, you can change the following properties: gxColor, pen size, and fill.
  9.     
  10.     NOTES:
  11.     • This file requires the following files to run correctly:
  12.         "graphics shell.c", "ColorLibrary.c", "FontLibrary.c", "GraphicsDebugLibrary.c",  "oval library.c", 
  13.         "OvalLibrary.c", "ShapeLibrary.c", "TransformLibrary.c".
  14.  
  15.     • For ideal printing of this file, please print in "landscape".
  16.     
  17.     Change History:
  18.  
  19.        4/96    bob        Updated #includes to support changed GX Library names.
  20.                     Updated the note regarding the files needed to run.
  21.                     Updated the copyright date.
  22.  
  23.     ©1990 -1996 Apple Computer, Inc.
  24.     All rights reserved.
  25. */
  26.  
  27. #include <Events.h>
  28. #include <Windows.h>
  29.  
  30. #include "FontLibrary.h"
  31. #include <GXEnvironment.h>
  32. #include "GraphicsLibraries.h"
  33. #include "QDLibrary.h"
  34. #include "graphics shell.h"
  35.  
  36. #define kFrameWidth ff(7)
  37.  
  38. //
  39. //  Set up the title and size of the window 
  40. //
  41. Rect     gWindowQDRect  = {50, 20, 450, 600};
  42. Str255     gWindowTitle = "\pPaths & Frames";
  43.  
  44. //
  45. //    If gDebugging = TRUE, graphics library errors and notices will be posted.  This functionality  will only work with 
  46. //    the "debugging" version of the QuickDraw GX init.  If this version of the init is not installed, nothing bad will happen, 
  47. //    but these  functions will not work. 
  48. //
  49. Boolean        gDebugging = true;
  50.  
  51.  
  52. //
  53. //     Set  "gGiveMeValidation" to TRUE, if you will receive run-time validation.  
  54. //
  55. Boolean        gGiveMeValidation = true;
  56.  
  57.  
  58. //
  59. //    gGraphicsHeapSize sets the size of the graphics gxHeap created by calling the GXNewGraphicsClient routine
  60. //    in main () within graphics shell.c.  You can determine the amount of graphics gxHeap required by using GraphicsBug.
  61. //    With  gGraphicsHeapSize set to 55k, I had 5 free blocks left in the graphics gxHeap. Sounds good to me.
  62. //
  63. long        gGraphicsHeapSize = 55;
  64.  
  65. gxShape     gOvaloidShape;
  66. gxShape     gTextMessageShape;
  67. Boolean     gDrawState = true;
  68.  
  69.  
  70. /*------ DoInitialization ---------------------------------------------------------------------------------*/
  71.  
  72. void DoInitialization(aWindow)
  73. WindowPtr aWindow;
  74. {    gxRectangle     ovalGeometricData = {ff(50), ff(150), ff(150), ff(195)};
  75.     gxShape            diamond, letterE;
  76.     
  77.     InitCommonColors ();
  78.  
  79.     //
  80.     //    Draw a message to the window which tells the user to click within the window for a change.
  81.     //
  82.     gTextMessageShape = GXNewText(35,(unsigned char*)"Click in the window for a change...",  nil);
  83.     SetShapeCommonFont(gTextMessageShape, timesFont);
  84.     GXSetShapeTextSize(gTextMessageShape, ff(20));
  85.     GXMoveShapeTo (gTextMessageShape, ff(165), ff(390)); 
  86.  
  87.     gOvaloidShape = NewOval(&ovalGeometricData);
  88.     GXRotateShape(gOvaloidShape, ff(20), ff(50), ff(150));
  89.  
  90.     diamond = GXNewRectangle(&ovalGeometricData);
  91.     GXRotateShape(diamond, ff(45), ff(20), ff(170));
  92.     AddToShape(gOvaloidShape, diamond);
  93.     
  94.     
  95.     letterE = GXNewText(1,(unsigned char*)"E", nil);
  96.     SetShapeCommonFont(letterE, timesFont);
  97.     GXSetShapeTextSize(letterE, ff(100));
  98.     GXSetShapeType(letterE, gxPathType);
  99.     GXInsetShape(letterE, -ff(5));
  100.     GXSkewShape(letterE, 0, ff(2), 0, 0);
  101.     GXMoveShapeTo(letterE, ff(40), ff(200));
  102.     AddToShape(gOvaloidShape, letterE);
  103.     
  104.     //
  105.     //    We can now dispose of our diamond and letterE shapes becasue they are now part of the 
  106.     //    geometry contained within our "gOvaloidShape" gxShape.
  107.     GXDisposeShape(diamond);
  108.     GXDisposeShape(letterE);
  109. }
  110.  
  111.  
  112.  
  113. /*------ DoDraw ---------------------------------------------------------------------------------------*/
  114.  
  115. void DoDraw(aWindow)
  116. WindowPtr aWindow;
  117. {
  118.     GXDrawShape(gTextMessageShape);
  119.     
  120.     GXMoveShapeTo(gOvaloidShape, ff(25), ff(100));
  121.     
  122.     if (gDrawState) {
  123.         GXSetShapeFill(gOvaloidShape, gxEvenOddFill);
  124.         GXDrawShape(gOvaloidShape);
  125.         
  126.         GXMoveShape(gOvaloidShape, ff(130), ff(-80));
  127.         GXSetShapeFill(gOvaloidShape, gxWindingFill);
  128.         GXDrawShape(gOvaloidShape);
  129.         
  130.         GXMoveShape(gOvaloidShape, ff(130), ff(80));
  131.         GXSetShapeFill(gOvaloidShape, gxClosedFrameFill);
  132.         GXDrawShape(gOvaloidShape);
  133.         
  134.         GXMoveShape(gOvaloidShape, ff(130), ff(-80));
  135.         GXSetShapePen(gOvaloidShape, ff(5));
  136.         GXSetShapeFill(gOvaloidShape, gxClosedFrameFill);
  137.         GXDrawShape(gOvaloidShape);
  138.     } else {
  139.  
  140.         //
  141.         //  We ignore these notices because we want to change the color, attributes and pen size.  If we did not, nothing
  142.         //    bad would happen, but you would receive the notice. You can ignore _all_ notices or warnings posted.
  143.         //
  144.         GXIgnoreGraphicsNotice(color_already_set);
  145.         GXIgnoreGraphicsNotice(attributes_already_set);
  146.         GXIgnoreGraphicsNotice(pen_already_set);
  147.  
  148.         GXSetShapeFill(gOvaloidShape, gxClosedFrameFill);
  149.         GXSetShapeStyleAttributes(gOvaloidShape, gxCenterFrameStyle);
  150.         GXSetShapePen(gOvaloidShape, kFrameWidth);
  151.         SetShapeCommonColor(gOvaloidShape, red);  
  152.         GXDrawShape(gOvaloidShape);
  153.         
  154.         GXSetShapePen(gOvaloidShape, 0);
  155.         SetShapeCommonColor(gOvaloidShape, gxBlack); 
  156.         GXDrawShape(gOvaloidShape);
  157.         
  158.         GXMoveShape(gOvaloidShape, ff(190), ff(-80));
  159.         GXSetShapeStyleAttributes(gOvaloidShape, gxInsideFrameStyle);
  160.         GXSetShapePen(gOvaloidShape, kFrameWidth);
  161.         SetShapeCommonColor(gOvaloidShape, blue);
  162.         GXDrawShape(gOvaloidShape);
  163.         
  164.         GXSetShapePen(gOvaloidShape, 0);
  165.         SetShapeCommonColor(gOvaloidShape, gxBlack);  
  166.         GXDrawShape(gOvaloidShape);
  167.         
  168.         GXMoveShape(gOvaloidShape, ff(190), ff(80));
  169.         GXSetShapeStyleAttributes(gOvaloidShape, gxOutsideFrameStyle);
  170.         GXSetShapePen(gOvaloidShape, kFrameWidth);
  171.         SetShapeCommonColor(gOvaloidShape, green);
  172.         GXDrawShape(gOvaloidShape);
  173.         
  174.         GXSetShapePen(gOvaloidShape, 0);
  175.         SetShapeCommonColor(gOvaloidShape,  gxBlack); 
  176.         GXDrawShape(gOvaloidShape);
  177.  
  178.         //
  179.         //    We need to balance all of our GXIgnoreGraphicsNotice calls with GXPopGraphicsNotice calls,
  180.         //    thereby preventing the notice stack from overflowing.
  181.         GXPopGraphicsNotice(); 
  182.         GXPopGraphicsNotice();
  183.         GXPopGraphicsNotice();
  184.     }
  185. }
  186.  
  187.  
  188. /*------ DoDispose -------------------------------------------------------------------------------------*/
  189.  
  190. void DoDispose(aWindow)
  191. WindowPtr aWindow;
  192. {
  193.     //  
  194.     //    You should always dispose of your GX graphics objects before tossing your window. Why? It's generally good 
  195.     //    form and this approach guarantees that everything is disposed. If you had not disposed of everything, the
  196.     //    call to DisposeWindow should dispose of the objects. If you are running the debugging version of the 
  197.     //    SecretGraphics init with notices set, you will receive a notice that you had not disposed of everything. You
  198.     //    can turn notices on in this file by setting gDebugging = TRUE (above).
  199.     //  
  200.     GXDisposeShape(gOvaloidShape);
  201.     GXDisposeShape(gTextMessageShape);
  202.     GXDisposeShape(gWindowBoundsShape);
  203.     DisposeCommonColors();
  204.        DisposeWindow(aWindow);
  205. }
  206.     
  207.  
  208. /*------ DoClick ---------------------------------------------------------------------------------------*/
  209.  
  210. void DoClick( orgMouseLoc, theWindow )
  211. gxPoint        orgMouseLoc;
  212. WindowPtr     theWindow;
  213. {
  214.     SetPort ( theWindow );
  215.     EraseRect( &theWindow->portRect );
  216.     
  217.     gDrawState = !gDrawState;
  218.     DoDraw( theWindow );
  219. }
  220.  
  221.  
  222. /*------ DoIdle ----------------------------------------------------------------------------------------*/
  223. void DoIdle(aWindow)
  224. WindowPtr aWindow;
  225. {
  226. }
  227.